﻿using System.Collections.Generic;
using System.ComponentModel;


namespace MyFloridaHouse.libSvOpenDistricts.Census
{
    /** 
     * NOTE: When using history,
     * you must call ChangeStarting() first
     * then call ChangeSave() every time a change is made
     * then call ChangeEnding() after the last reassignment in the set
     * */
    public class CensusGeometryHistory : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion

        #region properties

        public bool isUndoAvailable
        {
            get
            {
                if (undoList != null)
                    return (undoList.Count > 0);
                else
                    return false;
            }
        }
        #endregion


        private List<CensusGeometryHistoryChange> undoList = new List<CensusGeometryHistoryChange>();

        public CensusGeometryHistory()
        {
        }

        internal void Reset()
        {
            undoList.Clear();
            NotifyPropertyChanged("isUndoAvailable");
        }

        public void ChangeStarting()
        {
            undoList.Clear();
        }

        public void ChangeComplete()
        {
            NotifyPropertyChanged("isUndoAvailable");
        }

        public void SaveChange(int oldDistrictID, int newDistrictID, int uogID )
        {
            undoList.Add(new CensusGeometryHistoryChange(oldDistrictID, newDistrictID, uogID));
        }

        public List<CensusGeometryHistoryChange> GetChangeList()
        {
            List<CensusGeometryHistoryChange> changeList = new List<CensusGeometryHistoryChange>();
            foreach (var chng in undoList)
            {
                changeList.Add(chng);
            }

            return changeList;

        }

    }
}
